package com.eureka;

import com.netflix.appinfo.*;
import com.netflix.discovery.*;

import java.util.UUID;

public class ES2 {
    public static void main(String[] args) {
//        EurekaClientConfig clientConfig = new EurekaClientConfig();
//        clientConfig.setRegistryRefreshIntervalMs(30000); // 设置刷新间隔时间
//        clientConfig.setServiceUrl(new HashMap<String, String>() {{
//            put("defaultZone", "http://localhost:8761/eureka/");
//        }});
//        EurekaTransportConfig transportConfig = new EurekaTransportConfig();
//        EurekaClient eurekaClient = new DiscoveryClient(clientConfig, transportConfig);
//        DiscoveryManager.getInstance().initComponent(new Object(), eurekaClient); // 初始化Eureka客户端组件


        // 1. 构建实例配置
        DataCenterInfo dataCenterInfo = new MyDataCenterInfo(DataCenterInfo.Name.MyOwn);
        InstanceInfo instance = InstanceInfo.Builder.newBuilder()
                .setInstanceId("service1:8080")
                .setAppName("SERVICE-A")
                .setHostName("localhost")
                .setIPAddr("192.168.1.100")
                .setPort(8080)
                .setDataCenterInfo(dataCenterInfo)
                .build();

// 2. 初始化客户端
        ApplicationInfoManager infoManager = new ApplicationInfoManager(
                new MyDataCenterInstanceConfig(),
                instance
        );
        InstanceInfo info = infoManager.getInfo();
        EurekaClient client = new DiscoveryClient(
                infoManager,
                new DefaultEurekaClientConfig()
        );
        infoManager.setInstanceStatus(InstanceInfo.InstanceStatus.UP);
        InstanceInfo nextServerFromEureka = client.getNextServerFromEureka("SERVICE-A", false);
        System.out.println(nextServerFromEureka);

    }
}